package org.xq.softcup.mq.client.message;

import lombok.Data;
import lombok.ToString;
import org.xq.softcup.mq.client.util.GenerateId;

import java.io.Serializable;
import java.util.Date;

/**
 * @author admin
 */
@ToString
@Data
public class MqMessage implements Serializable {
	private static final long serialVersionUID = 42L;

	private String id;				// 消息ID,
	private String topic;			// 消息主题
	private String group;			// 消息分组, 分组一致时，消息仅消费一次；存在多个分组时，广播消费；
	private String data;			// 消息数据
	private String status;			// 消息状态
	private int retryCount;			// 重试次数, 执行失败且大于0时生效，每重试一次减一；
	private long shardingId;		// 分片ID, 大于0时启用，否则使用消息ID；消费者通过该参数进行消息分片消费；分片ID不一致时分片并发消费；
	private int timeout;			// 超时时间，单位秒；大于0时生效，处于锁定运行状态且运行超时时，将主动标记运行失败；
	private Date effectTime;		// 生效时间, new Date()立即执行, 否则在生效时间点之后开始执行;


	public MqMessage() {
	}

	public MqMessage(String topic, String data) {
		this.topic = topic;
		this.data = data;
		this.id = GenerateId.generateId();
	}

	public MqMessage(String topic, String data, Date effectTime) {
		this.topic = topic;
		this.data = data;
		this.effectTime = effectTime;
	}

	public MqMessage(String topic, String data, long shardingId) {
		this.topic = topic;
		this.data = data;
		this.shardingId = shardingId;
	}

	// 复制消息对象
	public MqMessage(MqMessage mqMessage) {
		this.id = mqMessage.id;
		this.topic = mqMessage.topic;
		this.group = mqMessage.group;
		this.data = mqMessage.data;
		this.status = mqMessage.status;
		this.retryCount = mqMessage.retryCount;
		this.shardingId = mqMessage.shardingId;
		this.timeout = mqMessage.timeout;
		this.effectTime = mqMessage.effectTime;
	}

}
